package com.epidemy

import java.net.InetAddress
import scala.actors.remote.{Node, RemoteActor}

object LocalRemoteActors {
  protected var port = 8081
  protected val maxPort = 0xffff
  lazy val alive = {
    var connected = false
    while (!connected && port <= maxPort) {
      try {
        RemoteActor.alive(port)
        connected = true
        //println("RemoteActor listening on port " + port)
      } catch {
        case _ =>
        port += 1
      }
    }
    connected
  }
  lazy val localNode = if (!alive)
    error("Not alive !")
  else {
    Node(Grid.localAddress, port)
  }
}